import {
  get,
  post,
  put,
} from "./base_service"


/**
 * 入驻相关接口
 *
 * allen  2021-08-21
 */


/**
 * 创建公司入驻申请
 * @param {*} data 
 */
const createCompanyEnter = (data) => {
  return new Promise((resolve, reject) => {
    post("/join/create/company", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}



/**
 * 创建全民入驻申请
 * @param {*} data 
 */
const createFullNameEnter = (data) => {
  return new Promise((resolve, reject) => {
    post("/join/create/qm", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 创建经纪人入驻申请
 * @param {*} data 
 */
const createAgentEnter = (data) => {
  return new Promise((resolve, reject) => {
    post("/join/create/agent", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 创建置业顾问入驻申请
 * @param {*} data 
 */
const createAdviserEnter = (data) => {
  return new Promise((resolve, reject) => {
    post("/join/create/adviser", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 查询全民入驻详情
 */
const queryFullNameEnterDetail = () => {
  return new Promise((resolve, reject) => {
    get("/join/qm/detail").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 查询经纪人入驻详情
 */
const queryAgentEnterDetail = () => {
  return new Promise((resolve, reject) => {
    get("/join/agent/detail").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 查询置业顾问入驻详情
 */
const queryAdviserEnterDetail = () => {
  return new Promise((resolve, reject) => {
    get("/join/adviser/detail").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 查询公司入驻详情
 */
const queryCompanyEnterDetail = () => {
  return new Promise((resolve, reject) => {
    get("/join/company/detail").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 更新公司入驻信息
 * @param {*} data 
 */
const updateCompanyEnterInfo = (data) => {
  return new Promise((resolve, reject) => {
    put("/join/update/company", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 * 更新置业顾问入驻信息
 * @param {*} data 
 */
const updateAdviserEnterInfo = (data) => {
  return new Promise((resolve, reject) => {
    put("/join/update/adviser", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 更新全民入驻信息
 * @param {*} data 
 */
const updateFullNameEnterInfo = (data) => {
  return new Promise((resolve, reject) => {
    put("/join/update/qm", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 更新经纪人入驻信息
 * @param {*} data 
 */
const updateAgentEnterInfo = (data) => {
  return new Promise((resolve, reject) => {
    put("/join/update/agent", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 查询公司是否已入驻
 * @param {*} companyName 
 */
const enterCompanySearch = (companyName) => {
  return new Promise((resolve, reject) => {
    get("/join/search/company?companyName=" + companyName).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}




module.exports = {
  createCompanyEnter,
  createFullNameEnter,
  createAgentEnter,
  createAdviserEnter,
  queryFullNameEnterDetail,
  queryAdviserEnterDetail,
  queryAgentEnterDetail,
  queryCompanyEnterDetail,
  updateCompanyEnterInfo,
  updateAdviserEnterInfo,
  updateFullNameEnterInfo,
  updateAgentEnterInfo,
  enterCompanySearch
}

